#include "StdAfx.h"
#include "Node.h"
using namespace std;


int inte=4;
int ruch=5;
//Node::Node(string Name,int x,int y,int Colour)
/*4.05 Pawel*/Node::Node(string Name,int Colour,bool Strona)
{
    X=0;
	Y=0;
	strona=Strona;
	colour=Colour;
	visible = true;
/*30.04 Pawel*/	Height=0;
/*3.05 Pawel*/	hightlighted=false;
	father=NULL;
	previous=NULL;
	next=NULL;
	last=NULL;
	first=NULL;
//	Childrens=0;
	focus=false;
	link=false;
	hasNote=false;
	readOnly=false;
	ostatnio=NULL;
	this->changeNodeName(Name);
	//koniec
}

Node::Node() {Width=0;Height=0;}
Node::~Node(void)
{
}
//od tad dopisalem

void Node::addChild(string Name,Node *n,bool zp)
{
	Node *tmp,*tmp2;
	if(!father&&zp)
	{
		if(n->strona)
		{
			first->addChild(Name,n,zp);
//			n->wzgledna(n->X,n->Y);				/*moze sie przydac ale narazie wole bez */
			n->X=X+getWidth()+30;
//			n->bezwzgledna(n->X,n->Y);
		}
		else
			last->addChild(Name,n,zp);
		return;
	}
	n->father=this;
	if(last==NULL)
	{
		tmp=this;
		last=n;
		first=n;
		if(n->strona)
			n->X=X+this->getWidth()+30; //RemboL : to zmienilem
		else
			n->X=X-30-n->getWidth();
/*30.04*/		n->Y=Y+this->getHeight()/2-n->getHeight()/2;
		if(zp&&father&&father->father)
		{
			int g=n->getHeight()/2;
			int d=n->getHeight()/2;
			if(g<0) g=0;
			if(d<0) d=0;
			n->zwezanie(0,-g,-d);
		}

//3.05 Pawel do		
	}
	else
	{
		tmp=this->last;
		this->last=n;
		n->previous=tmp;
		tmp->next=n;
		
		tmp2=tmp;
		while(tmp2!=NULL)
		{
			if((tmp2->Y+tmp2->Height)>(tmp->Y+tmp->Height))
				tmp=tmp2;
			tmp2=tmp2->last;
		}
		if(n->strona)
			n->X=X+this->getWidth()+30;	//RemboL: to tez
		else
			n->X=X-n->getWidth()-30;
/*3.05*/		n->Y=tmp->Y+tmp->Height-n->Height/2+inte;
//		n->Y=b+inte;
//1.05 Pawel od		
		if(zp&&tmp&&tmp->father&&tmp->father->father)
		{
			int g=n->Height/2+inte, d=n->Height/2+inte;
			if(g<0) g=0;
			if(d<0) d=0;
			n->zwezanie(0,-g,-d);
		}
	}
	focus=false;
	n->focus=true;

}

void Node::addBrother(string Name,Node *n,bool zp)
{
	Node *tmp,*tmp2;
	if(father!=NULL){
		n->father=father;
		n->next=next;
		n->previous=this;
		if(next==NULL){
			father->last=n;
		}
		else
		{
			next->previous=n;
		}
		next=n;

		if(n->strona)
			n->X=X;
		else n->X=X+Width-n->Width;
//		/*30.04*/		n->Y=tmp->Y+tmp->Height-n->Height/2+inte;
		n->Y=max()-n->Height/2+inte;
		if(zp)
		{
			int g=n->Height/2+inte;
			int d=n->Height/2+inte;
			if(g<0) g=0;
			if(d<0) d=0;
			n->zwezanie(0,-g,-d);
		}
		focus=false;
		n->focus=true;
	}
	else
		this->addChild(Name,n);
}


Node* Node::inLeft()
{
		if(father!=NULL)
		{
			if(father->father&&father->father->father)
			{
				focus=false;
				father->focus=true;
				father->ostatnio=this;
				return father;
			}
			else
			{
				if(father->father)
				{
					focus=false;
					father->father->focus=true;
					father->ostatnio=this;
					return father->father;
				}
				else
				{
					focus=false;
					father->focus=true;
					return father;
				}
			}
		}
		else
		{
//			return last->inRight();
			return this;
		}
}
Node* Node::inUp()
{
	if(previous!=NULL)
	{
		focus=false;
		previous->focus=true;
		return previous;
	}
	else return this;
}
Node* Node::inDown()
{
	if(next!=NULL)
	{
		focus=false;
		next->focus=true;
		return next;
	}
	else return this;
}
Node* Node::inRight()
{	
	if(!visible) return this;
	if(ostatnio==NULL)
	{
		if(first==NULL)
			return this;
		else
		{
			focus=false;
			if(first->next==NULL)
			{
				first->focus=true;
				return first;
			}
			else
			{
				Node *tmp = first;
				bool t=true;
				while((tmp->next!=NULL)&&t)
				{
					int a=(tmp->X-X)*(tmp->X-X)+(tmp->Y-Y)*(tmp->Y-Y);
					int b=(tmp->next->X-X)*(tmp->next->X-X)+(tmp->next->Y-Y)*(tmp->next->Y-Y);
					if(a<=b) t=false;
					tmp=tmp->next;
				}
				tmp=tmp->previous;
				tmp->focus=true;
				return tmp;
			}
		}
	}
	else
	{
		focus=false;
		ostatnio->focus=true;
		return ostatnio;
	}
}

/*30.04*/void Node::rozszerzanie(Node *n,int h,int typ) //0 - bez zmian, 1- w gore, 2 - w dol;
{
	Node *tmp;
	if(typ==0)
	{
		tmp=n->previous;
		while(tmp!=NULL)
		{
/*30.04*/			rozszerzanie(tmp,h,1);
			tmp=tmp->previous;
		}
		tmp=n->next;
		while(tmp!=NULL)
		{
/*30.04*/			rozszerzanie(tmp,h,2);
			tmp=tmp->next;
		}
		if(n->father!=NULL)
		{
/*30.04*/			rozszerzanie(n->father,h,0);
		}
	}
	if (typ==1)
	{
		tmp=n->first;
		while(tmp!=NULL)
		{
/*30.04*/			rozszerzanie(tmp,h,1);
			tmp=tmp->next;
		}
/*30.04 Pawel*/		n->Y=n->Y-h/2-inte;
	}
	if(typ==2)
	{
		tmp=n->first;
		while(tmp!=NULL)
		{
/*30.04*/			rozszerzanie(tmp,h,2);
			tmp=tmp->next;
		}
/*30.04 Pawel*/		n->Y=n->Y+inte+h/2;
	}

}

void Node::uncheck()
{
	Node *tmp;
	if(father!=NULL)
	{
		tmp=father->first;
		while(tmp!=NULL)
		{
			hightlighted=false;
			tmp=tmp->next;
		}
	}
}
void Node::visibility()
{
//Pawel 13.03.07 od
	if(visible) this->setInvisible();
	else this->setVisible();;
// Pawel 13.03.07 do
}


//Pawel 13.03.07 od
Node* Node::remove()
{
	if(!father) return this;
	else 
	{
//4.05 Pawel od
		int minimum1=this->min(),maksimum1=this->max(),minimum2,maksimum2;
		Node* tmp2=father;
		while(tmp2&&!tmp2->next&&!tmp2->previous)
		{
			tmp2=tmp2->father;
		}
		if(tmp2)
		{
			minimum2=tmp2->min();
			maksimum2=tmp2->max();
		}
		int g=Y+Height/2-minimum1,d=maksimum1-Y-Height/2;
		if(g<0) g=0;
		if(d<0) d=0;
		if(next||previous)
		{
			Node *tmp=previous;
			while(tmp)
			{
				tmp->zwezanie(1,g+inte,d+inte);
				tmp=tmp->previous;
			}
			tmp=next;
			while (tmp)
			{
				tmp->zwezanie(-1,g+inte,d+inte);
				tmp=tmp->next;
			}
		}
//4.05 Pawel do
		Node *brat=this->previous;
		if(!brat)	father->first=this->next;
		else{
			brat->next=this->next;
			this->father->ostatnio=brat;
		}
		brat=this->next;
		if(!brat)	father->last=this->previous;
		else{
			brat->previous=this->previous;
			this->father->ostatnio=brat;
		}
//4.05 Pawel od
		if(tmp2&&tmp2->father&&tmp2->father->father)
		{
			int g=tmp2->min()-minimum2, d=maksimum2-tmp2->max();
			if(g<0) g=0;
			if(d<0) d=0;
			tmp2->zwezanie(0,g,d);
		}
//4.05 Pawel do
		if(next)
		{
			next->focus=true;
			return next;
		}
		if(previous)
		{
			previous->focus=true;
			return previous;
		}
		father->focus=true;
		return father;
	}
}

//Bury 10.04.07 od
/*funkcja check - opis w Node.h
przy poszukiwaniu czy kliknelismy na noda przy pierwszym uruchomieniu nako n przekazywany
jest root pozniej wskazniki to korzeni poddrzew
x i y to wspolrzedne klikniecia 
sprawdzamy czy x i y lezy w prostokacie do ktorego umownie nalezy node
UWAGA: tutaj dziala ladnie przy tej czcionce!!! przy kazdym nodzie wspolrzedne Y wskazuja o 10
za malo tzn to pixeli powyzej lewego gornego rogu NAPISU czyli litery
byc moze jest to spowodowane rootem gdyz akurat u niego X i Y wskazuja dokladnie na lewy 
gorny rog progtokata czy ramki co go otacza, 
JEZELI WIEC BEDZIEMY PLANOWAC ROZNEJ WIELKOSCI CZCIONKI BEDZIE SIE TRZEBA NAD TYM ZASTANOWIC
podejrzewam rowniesz ze zmienic bardzo duzo w programie:/
KONIEC UWAGI:P*/
void Node::wzgledna(int x,int y)
{
	if(this->visible)
	{
		Node* tmp=first;
		while(tmp)
		{
			tmp->wzgledna(x,y);
			tmp->X=tmp->X-x;
			tmp->Y=tmp->Y-y;
			tmp=tmp->next;
		}
	}
}

void Node::bezwzgledna(int x,int y)
{
	if(this->visible)
	{
		Node* tmp=first;
		while(tmp)
		{
			tmp->bezwzgledna(x,y);
			tmp->X=tmp->X+x;
			tmp->Y=tmp->Y+y;
			tmp=tmp->next;
		}
	}
}

void Node::zwezanie(int typ,int gora,int dol)	//typ 0-bez zmian, 1 - w gore, -1 w dol;
{									//h>0 zwezanie h<0 rozszerzanie
	Node *tmp;
	if(typ==0)
		{
			if(gora<0)
			{
				if(visible&&first)
				{		
					int g=first->min()-Y;
					if(g<gora) 
					{
					}
					else if(g>=0)
					{
						gora=0;
					}
					else
						gora=g;
				}
				
			}
			if(dol<0)
			{
				if(visible&&last)
				{
					int d=Y+this->Height-last->max();
					if(d<dol) 
					{
					}
					else if(d>=0)
					{
						dol=0;
					}
					else
						dol=d;
				}
			}
			if(gora>0)
			{
				if(visible&&first)
				{
					int g=gora-first->min()+min();
					if(g<0) g=0;
					gora=g;
				}
			}
			if(dol>0)
			{
				if(visible&&last)
				{
					int d=dol-max()+last->max();
					if(d<0) d=0;
					dol=d;
				}
			}
			tmp=this->previous;
			while(tmp)				
			{
				tmp->zwezanie(1,gora,dol);
				tmp=tmp->previous;
			}
			tmp=this->next;
			while(tmp)
			{
				tmp->zwezanie(-1,gora,dol);
				tmp=tmp->next;
			}
			if(father&&father->father&&father->father->father) father->zwezanie(0,gora,dol);
		}
	else
		{
			if(visible)
			{
				tmp=first;
				while(tmp)
				{
					tmp->zwezanie(typ,gora,dol);
					tmp=tmp->next;
				}
			}
			if(typ>0) Y=Y+gora;
			else Y=Y-dol;
		}
	
}

int Node::max()
{
	Node *tmp=this;
/*30.04*/	int m=Y+Height;
	while(tmp->last&&tmp->visible)
	{
		tmp=tmp->last;
/*30.04*/		if(m<(tmp->Y+tmp->Height)) m=tmp->Y+tmp->Height;
	}
	return m;
}

int Node::min()
{
	Node *tmp=this;
	int m=Y;
	while(tmp->first&&tmp->visible)
	{
		tmp=tmp->first;
		if(m>tmp->Y) m=tmp->Y;
	}
	return m;
}
//28.03.2007 Pawel do

//29.03.2007 Pawel od






void Node::setVisible()
{
	if(!visible)
	{
		visible=true;
		if(strona)
			bezwzgledna(X+Width,Y+Height/2);
		else
			bezwzgledna(X,Y+Height/2);
		int minimum=this->min(),maksimum=this->max();
//30.04 Pawel od
		int a,b;
		Node* tmp=this;
		a=tmp->Y;
		b=tmp->Y+tmp->Height;
		while (!tmp->next&&!tmp->previous&&tmp->father)
		{
			tmp=tmp->father;
			if(a>tmp->Y) a=tmp->Y;
			if(b<(tmp->Y+tmp->Height)) b=tmp->Y+tmp->Height;
		}
		int g=a-minimum, d=maksimum-b;
		if(g<0) g=0;
		if(d<0) d=0;
		zwezanie(0,-g,-d);
//30.04 Pawel do
	}
}

void Node::setInvisible()
{
	if(visible)
	{
		int minimum=this->min(),maksimum=this->max();
		if(strona)
			wzgledna(X+Width,Y+Height/2);
		else
			wzgledna(X,Y+Height/2);
		visible=false;
//30.04 Pawel od
		int a,b;
		Node* tmp=this;
		a=tmp->Y;
		b=tmp->Y+tmp->Height;
/*		while (!tmp->next&&!tmp->previous&&tmp->father)
		{
			tmp=tmp->father;
			if(a>tmp->Y) a=tmp->Y;
			if(b<(tmp->Y+tmp->Height)) b=tmp->Y+tmp->Height;
		}*/
		int g=a-minimum, d=maksimum-b;
		if(g<0) g=0;
		if(d<0) d=0;
		zwezanie(0,g,d);
//30.04 Pawel do
	}
}

Node* Node::check(Node *n, int X, int Y)
{
	Node *tmp=n;
	Node *tmpReturn=NULL;
	int x=X;
	int y=Y;
//2.05 Pawel od
	if(!(tmp->father))
	if ((tmp->getX()-3<=x)&&((tmp->getX()+tmp->getWidth()+7)>=x)&&((tmp->getY()-6)<=y)&&((tmp->getY()+tmp->getHeight()+6)>=y))
	{
//		tmp->focus=true;
		return tmp;
	}
//2.05 Pawel do
	
/*30.04 Pawel*/		if ((tmp->getX()<=x)&&((tmp->getX()+tmp->getWidth())>=x)&&((tmp->getY())<=y)&&((tmp->getY()+tmp->getHeight())>=y))
		//jezeli lezy w prostokacie
		{
//2.05 Pawel			tmp->focus=true;
			return tmp;
		}
		else//jezeli nie to przeszukiwanie rekurencyjne
		{
			if(tmp->getVisible()){//jezeli jest widzialny
			tmp=n->first;
			
			while(tmp!=NULL)
				
			{
				tmpReturn=tmp->check(tmp, x, y);
				if (tmpReturn!=NULL) return tmpReturn; 
				tmp=tmp->next;
			}
			}
			return NULL;
		}
}
//Bury 10.04.07 do
Node* Node::kropoZnajdowacz(Node *n, int X, int Y)
{
	Node *tmp=n;
	Node *tmpReturn=NULL;
	int x=X;
	int y=Y;
	//(x+width+15, y+height/2)
	if ((!tmp->getVisible())&&(((tmp->getX()+tmp->getWidth()+15)<=x)&&((tmp->getX()+tmp->getWidth()+25)>=x)&&((tmp->getY()+(tmp->getHeight()/2)-5)<=y)&&((tmp->getY()+(tmp->getHeight()/2)+5)>=y)))
	{
		tmp->setVisible();
		return NULL;
	}
	else if((tmp->link)&&(((tmp->getX()+tmp->getWidth()+15)<=x)&&((tmp->getX()+tmp->getWidth()+25)>=x)&&((tmp->getY()+(tmp->getHeight()/2)-5)<=y)&&((tmp->getY()+(tmp->getHeight()/2)+5)>=y))) 
	{
		return tmp;
	}
	else
	{
		if(tmp->getVisible())
		{
			tmp=n->first;
			
			while(tmp!=NULL)
			{
				tmpReturn=tmp->kropoZnajdowacz(tmp, x, y);
				if (tmpReturn!=NULL) return tmpReturn; 
				tmp=tmp->next;
			}
		}
			return NULL;
	}		
}
void Node::nodeUp()
{
	if(!father)return;
	if(!next&&!previous)return;
	
	Node *tmp;
	if(previous)
	{
		tmp=previous;
		tmp->setInvisible();
//		tmp->wzgledna(tmp->X,tmp->Y);
		this->setInvisible();
//		this->wzgledna(this->X,this->Y);
		previous=tmp->previous;
		if(previous)
		{
			previous->next=this;
		}
		tmp->next=next;
		if(next)
		{
			next->previous=tmp;
		}
		next=tmp;
		tmp->previous=this;
		if(!tmp->next)
		{
			father->last=tmp;	
		}
		if(!previous)
		{
			father->first=this;
		}
//30.04 Pawel od
		int r;
		r=this->Y;
		this->Y=tmp->Y;
		tmp->Y=r-tmp->Height+this->Height;
//30.04 Pawel do
		tmp->setVisible();
//		tmp->bezwzgledna(tmp->X,tmp->Y);
		this->setVisible();
//		this->bezwzgledna(this->X,this->Y);
	}
	else
	{
		Node *tmp2=next;
		tmp=this;
		while(tmp)
		{
			tmp->setInvisible();
//			tmp->wzgledna(tmp->X,tmp->Y);
			tmp=tmp->next;
		}
		tmp=father->last;
		tmp->next=this;
		previous=tmp;
		next->previous=NULL;
		father->first=next;
		next=NULL;
		father->last=this;
		tmp=tmp2;
		while(tmp->next)
		{
//30.04 Pawel od
			int r=tmp->Y;
			tmp->Y=this->Y;
			this->Y=r+tmp->Height-Height;
			tmp=tmp->next;
//30.04 Pawel do
		}
		while(tmp2)
		{
			tmp2->setVisible();
//			tmp2->bezwzgledna(tmp2->X,tmp2->Y);
			tmp2=tmp2->next;
		}
	}
}

void Node::nodeDown()
{
	if(!father)return;
	if(!next&&!previous)return;
	
	Node *tmp;
	if(next)
	{
		tmp=next;
		tmp->setInvisible();
//		tmp->wzgledna(tmp->X,tmp->Y);
		this->setInvisible();
//		this->wzgledna(this->X,this->Y);
		next=tmp->next;
		if(next)
		{
			next->previous=this;
		}
		tmp->previous=previous;
		if(previous)
		{
			previous->next=tmp;
		}
		previous=tmp;
		tmp->next=this;
		if(!tmp->previous)
		{
			father->first=tmp;	
		}
		if(!previous)
		{
			father->last=this;
		}
		int r;
//30.04 Pawel od
		r=tmp->Y;
		tmp->Y=this->Y;
		this->Y=r+tmp->Height-Height;
//30.04 Pawel do
		tmp->setVisible();
//		tmp->bezwzgledna(tmp->X,tmp->Y);
		this->setVisible();
//		this->bezwzgledna(this->X,this->Y);

	}
	else
	{
		Node *tmp2=previous;
		tmp=this;
		while(tmp)
		{
			tmp->setInvisible();
//			tmp->wzgledna(tmp->X,tmp->Y);
			tmp=tmp->previous;
		}
		tmp=father->first;
		tmp->previous=this;
		next=tmp;
		previous->next=NULL;
		father->last=previous;
		previous=NULL;
		father->first=this;
		tmp=tmp2;
		while(tmp->previous)
		{
//30.04 Pawel od
			int r=this->Y;
			this->Y=tmp->Y;
			tmp->Y=r-tmp->Height+Height;
			tmp=tmp->previous;
//30..04 Pawel do
		}
		while(tmp2)
		{
			tmp2->setVisible();
//			tmp2->bezwzgledna(tmp2->X,tmp2->Y);
			tmp2=tmp2->previous;
		}
	}
}

//19.04.07 Pawel od
void Node::nodeLeft()
{
	if(!father||!father->father) return;
	Node *tmp=father,*tmp2;
	bool b=false;
	if(tmp->ostatnio==this)
		tmp->ostatnio=NULL;
	if(this->visible)
	{
		this->setInvisible();
		b=true;
	}
	tmp2=this->remove();
	tmp2->focus=false;
	this->father=NULL;
	this->next=NULL;
	this->previous=NULL;
	tmp->addBrother("",this);
	if(b)
	{
		this->setVisible();
	}
}

//19.04.07 Pawel do


void Node::moveX(int x)
{
	this->wzgledna(X,Y);
	if(x!=0)
	{
		if((x>0&&strona)||(x<0&&!strona))
		{
			X=X+x;
		}
		else
		{
			if(father)
			{
				if(strona)
				{
					int odleglosc;
					if(father->father&&!father->father->father)
						odleglosc=X-(father->father->X+father->father->getWidth());
					else
						odleglosc=X-(father->X+father->getWidth());
					if(odleglosc<=20) ;			//20 minimalna odstep miedzy nodami w poziomie; mozna zastapic stala
					else
					{
						odleglosc=odleglosc-20;
						if(odleglosc+x<0) X=X-odleglosc;
						else X=X+x;
					}
				}
				else
				{
					int odleglosc=father->X-X-getWidth();
					if(odleglosc<=20) ;
					else
					{
						odleglosc=odleglosc-20;
						if(odleglosc-x<0) X=X+odleglosc;
						else X=X+x;
					}

				}
			}
			else
				X=X+x;
		}
	}
	this->bezwzgledna(X,Y);
}

void Node::moveY(int y)
{
//	this->wzgledna(X,Y);
	bool t=this->visible;

	this->setInvisible();
	Y=Y-y;
//	this->bezwzgledna(X,Y);
	if(y<0)
	{
		int maximum=max();
		int ponizej;
		Node* tmp=this;
		while (tmp&&!tmp->next)
		{
			tmp=tmp->father;
		}
		if(tmp)
		{
			tmp=tmp->next;
			ponizej=tmp->Y;
			while(tmp&&tmp->father->visible)
			{
				if(tmp->Y<ponizej) ponizej=tmp->Y;
				tmp=tmp->first;
			}
//30.04 Pawel od
			if(ponizej-maximum<7)
				this->zwezanie(0,0,ponizej-7-maximum);
//30.04 Pawel do
		}
	}
	if(y>0)
	{
		int minimum=min();
		int powyzej;
		Node* tmp=this;
		while(tmp&&!tmp->previous)
		{
			tmp=tmp->father;
		}
		if(tmp)
		{
			tmp=tmp->previous;
//30.04 Pawel od
			powyzej=tmp->Y+tmp->Height;
			while(tmp&&tmp->father->visible)
			{
				if((tmp->Y+tmp->Height)>powyzej) powyzej=tmp->Y+tmp->Height;
				tmp=tmp->last;
			}
			if(minimum-powyzej<7)
				this->zwezanie(0,minimum-powyzej-7,0);
//30.04 Pawel do
		}
	}
	if(t)  this->setVisible();
}

void Node::move(int x,int y)
{
	moveX(x);
	moveY(y);
}

void Node::changeNodeName(string newNodeName)
{
//2.05 Pawel od
	int minp1,minp2,maxp1,maxp2,hp;   //wartosci minimalne i maksymalne drzewa przed zmiana nazwy
	Node* wezel,*wezel2;
	hp=Height;
/*	minp1=min();
	maxp1=max();
	wezel=father;
	while(wezel&&!wezel->next&&!wezel->previous) wezel=wezel->father;
	if(wezel)
	{
		minp2=wezel->min();
		maxp2=wezel->max();
	}*/
	if(this->strona)
	{
		if(this->father)
				wzgledna(X+Width,Y);
		else if (first) first->wzgledna(X+Width,Y);
	}
	else 
	{
		wzgledna(X,Y);
		X=X+getWidth();
	}
	int tmp=this->getWidth();
	NodeName=newNodeName;
	array<wchar_t,1> ^separator = {'\n'};
	array<System::String^,1>^ tmpStrings = (gcnew System::String(NodeName.c_str()))->Split(separator);
	int tmpWidth=tmpStrings[0]->Length;
	for (int i=1;i<tmpStrings->Length;++i)
		if (tmpStrings[i]->Length>tmpWidth)
			tmpWidth=tmpStrings[i]->Length;
	Width=(int)(tmpWidth*8.3);
	Height=15.1*tmpStrings->Length;
	if(this->strona)
	{
		if(father)
			bezwzgledna(X+Width,Y);
		else if(first)  first->bezwzgledna(X+Width,Y);
	}
	else
	{
		X=X-getWidth();
		bezwzgledna(X,Y);
	}
	if(Height-hp!=0)
	{
		Y=Y-(Height-hp)/2;
		this->zwezanie(0,(hp-Height)/2,(hp-Height)/2);
/*		if(Height-hp>0)
		{
			

			if(Y<minp1)
			{
				wezel2=previous;
				while(wezel2)
				{
					wezel2->zwezanie(1,Y-minp1,0);	
					wezel2=wezel2->previous;
				}
			}
			if(maxp1<Y+Height)
			{
				wezel2=next;
				while(wezel2)
				{
					wezel2->zwezanie(-1,0,maxp1-Y-Height);
					wezel2=wezel2->next;
				}
			}
		}
		else
		{
			
			int mink=min();
			if(mink>minp1)
			{
				wezel2=previous;
				while(wezel2)
				{
					wezel2->zwezanie(1,mink-minp1,0);
					wezel2=wezel2->previous;
				}
			}
			int maxk=max();
			if(maxp1>maxk)
			{
				wezel2=next;
				while(wezel2)
				{
					wezel2->zwezanie(-1,0,maxp1-maxk);
					wezel2=wezel2->next;
				}
			}
		}*/
/*		if(wezel)
			{
				int g=wezel->min()-minp2;
				int d=maxp2-wezel->max();
				wezel->zwezanie(0,g,d);
			}
*/
	}
	


//2.05 Pawel do
}

void Node::mirror()
{
	if(strona)
		strona=false;
	else
		strona=true;
	Node *tmp=first;
	while(tmp)
	{
		tmp->X=-tmp->X-tmp->Width;
		tmp->mirror();
		tmp=tmp->next;
	}
}

void Node::setStrona(bool s)
{
	strona=s;
	Node *tmp=first;
	while(tmp)
	{
		tmp->setStrona(s);
		tmp=tmp->next;
	}
}
